Ext.define('NIM.view.AssetChange.DismantleNEForm',{
					extend : 'Ext.panel.Panel',
					alias : 'widget.DismantleNE',
					id : 'dismantleNE',
					border : false,
					title : 'Dismantle NE',
					layout : 'fit',
					closable : true,
					layout : {
						type : 'border'
					},
					width : 1 * screen.width,
					height : 590,
					items : [
							{
								xtype : 'form',
								id : 'panelDismantleNE',
								title : 'Dismantle Ne Form',
								region : 'west',
								margin : '5 5 5 5',
								method : 'POST',
								url    : './Services/AssetChange/NE/Change/Add',
								collapsible : true,
								collapsed : true,
								width : 600,
								items : [
										{
											xtype : 'hiddenfield',
											cls : 'black',
											name : 'CHANGE_CATEGORY',
											value : 'DISMANTLE_NE',
											margin : '5 10 5 25',
											labelWidth : 100 / 1366 * screen.width,
											width : 300 / 1366 * screen.width,
											fieldLabel : 'Site ID',
											msgTarget : 'title',
											allowBlank : true,
											validateBlank : false

										},
										{
											xtype : 'fieldcontainer',
											cls : 'black',
											margin : '5 10 0 10',
											fieldLabel : 'SITE ID',
											labelWidth : 130 / 1366 * screen.width,
											width : 325 / 1366 * screen.width,
											layout : 'hbox',
											items : [
													{
														xtype : 'textfield',
														id : 'siteIdtDismantleNE',
														name : 'SOURCE_SITE_ID',
														margin : '0 5 0 0',
														width : 135,
														hideLabel : true,
														listeners: {
									                        change: function (obj, newValue, oldValue, eOpts) {
									                            var site_id = Ext.getCmp("siteIdtDismantleNE").getValue();
									                            Ext.getStore('AssetChange.CategoryOnSite').removeAll();
									                            Ext.getStore('AssetChange.CategoryOnSite').getProxy().url = './Services/AssetChange/CatOnSite/List?siteId='+site_id;
									                            Ext.getStore('AssetChange.CategoryOnSite').load();
									                        }
									                    }
														
													},
													{
														xtype : 'button',
														text : 'Browse',
														width : 50,
														handler : function() {
															openPopup("siteIdtDismantleNE","siteNameDismantleNE");

														}

													} ]
										},
										{
											xtype : 'textfield',
											fieldLabel : 'SITE NAME',
											id : 'siteNameDismantleNE',
											labelWidth : 130 / 1366 * screen.width,
											width : 325 / 1366 * screen.width,
											margin : '5 10 0 10'
										},
										{
											xtype : 'datefield',
											minDate : new Date(),
											format : 'Y/m/d',
											fieldLabel : 'DATE',
											name : 'CHANGE_DATE',
											labelWidth : 130 / 1366 * screen.width,
											width : 325 / 1366 * screen.width,
											margin : '5 10 0 10'
										},
										{
											xtype : 'combobox',
											fieldLabel:'DESTINATION TYPE',
											id : 'destinationTypeDismantleNE',
											name : 'DESTINATION_TYPE',
											margin : '5 10 0 10',
											store : [ [ 'WAREHOUSE', 'WAREHOUSE' ],
														[ 'VENDOR', 'VENDOR' ]],
											labelWidth : 130 / 1366 * screen.width,
											width : 325 / 1366 * screen.width,
											value :'WAREHOUSE'
										},
										{
											xtype : 'combobox',
											fieldLabel:'DESTINATION',
											id : 'destinationDismantleNE',
											name : 'DESTINATION',
											store : 'Administration.Warehouse',
											margin : '15 10 0 10',
											labelWidth : 130 / 1366 * screen.width,
											width : 325 / 1366 * screen.width,
											store : 'Administration.Warehouse',
											displayField : 'WH_CODE',
											valueField : 'WH_ID'
										},
										{																									
											xtype : 'combobox',
											fieldLabel : 'REASON',
											name : 'CR_ID',
											displayField : 'CHANGE_REASON',
											valueField : 'CR_ID',
											labelWidth : 130 / 1366 * screen.width,
											width : 325 / 1366 * screen.width,
											allowBlank : false,
											store : 'Administration.AssetChangeReason',
											margin : '5 10 0 10',
											listeners : {
												afterrender : function() {
													Ext.getStore('Administration.AssetChangeReason').removeAll();
													Ext.getStore('Administration.AssetChangeReason').getProxy().url = './Services/DataMaster/AssetChangeReason/List?CHANGE_CATEGORY=DISMANTLE_NE';
													Ext.getStore('Administration.AssetChangeReason').load();

												}
											},

										},
										{
								             xtype: 'fileuploadfield',
								             emptyText: 'Select a document to upload...',
								             name:'FILE',
								             fieldLabel: 'ATTACHMENT FILE',
								             buttonText: 'Browse',
								             labelWidth: 130/1366*screen.width,
								             width: 325/1366*screen.width,
								             margin:'5 10 0 10'
							            },
										{
											xtype : 'button',
											text : 'PROCESS',
											id : 'processdismantlene',
											margin : '10 10 10 10',
											handler : function() {
												this.up('form').getForm().submit({
																	waitMsg : 'Please Wait ....',
																	success : function(form,action) {
																			return_AssetChange(form, action,"assetdismantlene");
																			site_id_ne = Ext.getCmp('siteIdtDismantleNE').getValue();
												                    	    tempDataNE("assetdismantlene","AssetChange.TempStore");
												                            refreshAssetChange("AssetChange.AssetChangeRelNe","./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=DISMANTLE_NE");
												                            

																	},
																	failure : function(form,action) {
																			return_AssetChange(form, action,"assetdismantlene");
																			site_id_ne = Ext.getCmp('siteIdtDismantleNE').getValue();
												                    	    tempDataNE("assetdismantlene","AssetChange.TempStore");
												                            refreshAssetChange("AssetChange.AssetChangeRelNe","./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=DISMANTLE_NE");
												                            
																	}
																});
											},

										},
										{
											xtype : 'button',
											text : 'RESET',
											margin : '10 10 10 10',
											handler : function() {
												this.up('form').getForm().reset();
											},

										},
										{
							              	  xtype :'panel',
							              	  id    :'assetdismantlene',
							              	  border: false,
							              	  
							            }]

							},
							{
								xtype : 'gridpanel',
								region : 'center',
								id : 'table_DismantleNE',
								height : 590,
								// width : 400,
								titleAlign : 'center',
								margin : '5 5 5 0',
								border : true,
								forceFit : true,
								columnLines : true,
								store : 'AssetChange.AssetChangeStore',
								selType : 'checkboxmodel',
								title : 'Dismantle NE',
								columns : [ {
									dataIndex : 'change_category',
									text : 'CHANGE CATEGORY',
									align : 'left'
								}, {
									dataIndex : 'change_reason',
									text : 'REASON',
									align : 'left'
								}, {
									dataIndex : 'source_site_id',
									text : 'SOURCE SITE ID',
									align : 'left'
								}, {
									dataIndex : 'destination',
									text : 'DESTINATION',
									align : 'left'
								},{
			                   	    xtype: 'actioncolumn',
			                   	    text : 'DOCUMENT',
			                   	    align : 'center',
			                   	    renderer: function (value, metadata, record) {
			                   	    	var document = record.get('document');
			                   	    	if (document=="null"){
			                   	    		this.items[0].icon = '';
			                   	    	}else{
			                   	    		var typefile=document.split(".");
			                   	    		 if (typefile[1]=="pdf"){ 
			                   	    			 this.items[0].icon = 'images/pdf-icon.png'; 
			                   	    		 }else if (typefile[1]=="docx" || typefile[1]=="doc"){
			                   	    			 this.items[0].icon = 'images/Word-icon.png';  
			                   	    		 }else if (typefile[1]=="xlsx" || typefile[1]=="xls"){ 
			                   	    			 this.items[0].icon = 'images/Excel-icon.png';  
			                   	    		 }
			                   	    	}
			                   	    },
			                   	    items: [{
			                   	        tooltip: 'Show Document',
			                   	        handler: function (grid, rowIndex, colIndex) {
			                   	        	openFIle(grid,rowIndex);
			                   	        }
			                   	    }]
			                   	}],
								listeners : {
									afterrender : function() {
									refreshAssetChange("AssetChange.AssetChangeStore","./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=DISMANTLE_NE");

									},
									itemdblclick : function(grid, record) {
						            	  var change_id = record.get('change_id');
						            	  change_id_global = change_id;
						                		if(Ext.getCmp('panelDismantleNE').hidden == true) Ext.getCmp('panelDismantleNE').toggleCollapse(true);
						                		Ext.Ajax.request({
						                		    method: "GET",
						                		    dataType: "json",
						                		    url: "./Services/AssetChange/Change/Detail/"+change_id,
						                		    async: false	,
						                		    success: function(c) {
						                		    	var jsonResults= $.parseJSON(c.responseText);
						                		    	data = jsonResults.item[0];
						                		    	console.log (data);
						                		    	Ext.getCmp('panelDismantleNE').getForm().setValues(data);
						                		        }
						                		    });
						            	  Ext.getStore('AssetDataMaster.AssetNonSac').removeAll();
					                      Ext.getStore('AssetDataMaster.AssetNonSac').getProxy().url = './Services/AssetChange/Change/Details/List/'+change_id+'?start=0&limit=20';
					                      Ext.getStore('AssetDataMaster.AssetNonSac').load();
					                      ShowGridAsset("assetdismantlene");      
						            	  	
						                }
								},

								dockedItems : [
										{
											xtype : 'pagingtoolbar',
											dock : 'bottom',
											store : 'AssetChange.AssetChangeStore',
											displayInfo : true
										},
										{
											xtype : 'toolbar',
											dock : 'top',
											items : [
													{
														xtype : 'textfield',
														fieldLabel : 'KEYWORD',
														id : 'keywordDismantleNE',
														margin : '0 10 0 10',
														labelWidth : 60,
														enableKeyEvents : true,
														listeners : {
															keypress : function(form, e) {
																if (e.getKey() == 13) {
																	var keyword = Ext.getCmp("keywordDismantleNE").getValue();
									                            	searchAssetChange('AssetChange.AssetChangeStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=DISMANTLE_NE&keyword=',keyword);
																}

															}
														}
													},
													{
														xtype : 'button',
														text : 'SEARCH',
														id : 'buttonSearchDismantleNE',
														margin : '0 30 0 0',
														handler : function() {
															var keyword = Ext.getCmp("keywordDismantleNE").getValue();
							                            	searchAssetChange('AssetChange.AssetChangeStore','./Services/AssetChange/Change/Detail/List?CHANGE_CATEGORY=DISMANTLE_NE&keyword=',keyword);
														}
													},
													{
														xtype : 'button',
														text : 'ADD NEW',
														id : 'buttonAddDismantleNE',
														margin : '0 20 0 0',
														handler : function() {
															if (Ext.getCmp('panelDismantleNE').hidden == true)
																Ext.getCmp('panelDismantleNE').toggleCollapse(true);
														}

													},
													{
														xtype : 'button',
														text : 'REFRESH',
														margin : '0 20 0 0',
														handler : function() {
															refreshDismantle('DISMANTLE_NE');
														}

													}

											]
										} ]

							} ]
				});
